import { readFileSync } from 'node:fs'
import * as path from 'node:path'

import { BaseSeeder } from '@adonisjs/lucid/seeders'
import { fileURLToPath } from 'node:url'

export default class extends BaseSeeder {
  async run() {
    const inOutReport = readSqlFile('in_out_report.sql')
    const stockReport = readSqlFile('stock_report.sql')

    await Promise.all([inOutReport, stockReport].map((sql) => this.client.rawQuery(sql)))
  }
}

function readSqlFile(filePath: string) {
  const rootPath = path.dirname(fileURLToPath(import.meta.url))
  return readFileSync(path.resolve(rootPath, '../sql', filePath), 'utf-8')
}
